/* 
    This file is part of eJourn.

    eJourn is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    eJourn is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with eJourn; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/* Why me?
   This module allows for translation between the in memory dict objects and
   the disk saveable "xml" documents. 
   This should provide a very convenient, and reasonably efficient, method
   for savind and reading your own files for config and for saving user data.
*/

/* Overhead
   Making xml from dictionaries incurs some extra overhead:

   [Some of the following really screws up emacs coloring, so just ignore 
   the extra comment starts, they're needed]
   
#ifdef TEST1
  int c=0;
  for (c=0; c < 1024*100; ++c) {
	char *xml = elog_dict_to_xml(d, "<Junk>");
	free(xml);
  }
#endif
#ifdef TEST2
  int c=0;
  for (c=0; c < 1024*100; ++c) {
	char *xml = elog_xml_start("<Junk>", 500);
	elog_xml_printf(xml, "<Junk>.%s", "<bob>", "is fascinating");
	elog_xml_printf(xml, "<Junk>.%s", "<tracy>", "isn't fascinating");
	elog_xml_printf(xml, "<Junk>.%s", "<about bob>", "");
	elog_xml_printf(xml, "<Junk>.<about bob>.%s", "<bob likes what>",
					"I like donkeys");
	elog_xml_printf(xml, "<Junk>.<about bob>.%s", "<query>", "");
	elog_xml_printf(xml, "<Junk>.<about bob>.<query>.%s", "<and wha?>", "yes");
	free(xml);
  }

#endif

This resulted in:
[devel@rachelanne xml_dict]$ time ./test1

real    0m6.720s
user    0m5.688s
sys     0m0.156s
[devel@rachelanne xml_dict]$ time ./test1

real    0m6.313s
user    0m5.612s
sys     0m0.152s
[devel@rachelanne xml_dict]$ time ./test2

real    0m2.422s
user    0m2.336s
sys     0m0.000s
[devel@rachelanne xml_dict]$ time ./test2

real    0m2.459s
user    0m2.360s
sys     0m0.000s

As you can see the overhead cost is close to double that of simply building 
it yourself using the printf function.

Actual extra time cost, on an athlon 1800:  37 microseconds
Actual cost to build the cheapest way:      23 microseconds 

The document (readified):
<Junk>
  <about bob>
    <query>
      <and wha?>yes</and wha?>
    </query>
    <bob likes what>I like donkeys</bob likes what>
  </about bob>
  <tracy>isn't fascinating</tracy>
  <bob>is fascinating</bob>
</Junk>

*/

/* WARNING:
 * Any data in a dictionary marked as type DICT_TYPE_OBJ will 
 * 		not be exported to xml.
 */

#ifndef XML_DICT_H
#define XML_DICT_H
#include "../dict.h"
#include "../xml.h"

struct dict *elog_xml_to_dict(const char *xml);
//Pre:  xml is a legal c string containing xml text.
//Post:  dict will contain an equivalent representation with all values
//       accessable


/*	Note:  integers must be no more than 30 characters in length...	*/
char *elog_dict_to_xml(struct dict *dct, const char *meta);
//Pre:  dct is a value dictionary object.
//      meta is the name of the root tag
//Post:  returns a string which can be operated on using the elog_xml
//       functions.

#endif
